package com.yx.china.api;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yx.china.project.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "Global_FallbackMethod")
public class OrderApi {
    @Resource
    private PayService payService;
    @GetMapping("/order/get/{id}")
    public String getPayment(@PathVariable("id") Integer id){
        return payService.paymentInfo_OK(id);
    }

    @GetMapping(value = "/order/timeout/{id}")
    @HystrixCommand(fallbackMethod = "OrderFallBack")
    public String timeOut(@PathVariable("id") Integer id)  {
        int a=1/id;
        return payService.paymentInfo_TimeOut(id);
    }

    public String OrderFallBack(@PathVariable("id") Integer id){
        return "我是消费者-订单，计算出错，请稍后再试";
    }
    /**
     * 全局 fallback 方法
     * @return
     */
    public String Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试。/(╥﹏╥)/~~";
    }
}
